import React from 'react';
import { Table, Pagination } from 'antd';
import axios from 'axios'
import './adminList.css'
import { useState, useEffect } from "react";
export default function App() {
    let [shop, setshop] = useState()
    let [shops, setshops] = useState([])
    let pages = 1
    const columns = [
        {
            title: '姓名',
            dataIndex: 'user_name',
        },
        {
            title: '注册日期',
            dataIndex: 'create_time',
        },
        {
            title: '地址',
            dataIndex: 'city',
        },
        {
            title: '权限',
            dataIndex: 'admin',
        }
    ];
    useEffect(() => {
        axios.get('https://elm.cangdu.org/admin/count').then(res => {
            if (res.data.status == 1) {
                setshop(res.data.count)
            }
        })
        clk()
    }, []);
    function clk() {
        axios.get(`https://elm.cangdu.org/admin/all?offset=${(pages - 1) * 20}&limit=20`).then(res => {
            console.log(res);
            shops = res.data.data
            setshops([...shops])
        })

    }
    function change(page) {
        pages = page
        clk()
    }
    return <div className='main'>
        <Table
            columns={columns}
            pagination={false}
            rowKey={'create_time'}
            dataSource={shops}
        />
        <Pagination total={shop} showTotal={(shop) => `共${shop}条`}
            showSizeChanger={false} onChange={change} pageSize={shops.length} />
    </div>
}